<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" 
	xmlns:ui="http://java.sun.com/jsf/facelets" 
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core" 
	xmlns:p="http://primefaces.org/ui"  
	xmlns:cc="http://java.sun.com/jsf/composite">

	<cc:interface componentType="formEntityField">
		<cc:attribute name="label" required="true" />
		<cc:attribute name="field" required="true" />
		<cc:attribute name="backingBean" required="false" />
		<cc:attribute name="entity" required="false" />
		<cc:attribute name="childField" required="true" />
		<cc:attribute name="required" default="false" />
		<cc:attribute name="size" default="20" />
		<cc:attribute name="popup" default="false" />
		<cc:attribute name="disabled" default="false" />
		<cc:attribute name="listBean" />
		<cc:attribute name="edit" />
	</cc:interface>


	<cc:implementation>
		<ui:fragment rendered="#{cc.attrs.popup}">
				<p:outputLabel for="#{cc.attrs.id}" value="#{cc.attrs.label}" />
				<p:inputText id="#{cc.attrs.id}" rendered="#{cc.editMode}" value="#{cc.entityFromBackingBeanOrAttribute[cc.attrs.field][cc.attrs.childField]}" required="#{cc.attrs.required}" size="#{cc.attrs.size}" disabled="true" />
				<p:commandButton rendered="#{cc.editMode}" id="selectLink" onclick="dlg.show()" icon="ui-icon-search" />
				<p:tooltip for="selectLink" value="#{messages['commons.search']}" />
				<h:outputText rendered="#{not cc.editMode}" value="#{cc.entityFromBackingBeanOrAttribute[cc.attrs.field][cc.attrs.childField]}" style="font-weight:bold;" />
		</ui:fragment>
		
		<ui:fragment rendered="#{not cc.attrs.popup}">

			<!-- if service is set, then load list of all entities from db and show as drop down list -->
			<ui:fragment rendered="#{!empty cc.attrs.listBean}">
					<p:outputLabel for="#{cc.attrs.id}_level" value="#{cc.attrs.label}" />
					<h:selectOneMenu rendered="#{cc.editMode}" id="#{cc.attrs.id}_level" value="#{cc.entityFromBackingBeanOrAttribute[cc.attrs.field]}" required="#{cc.attrs.required}" styleClass="input-medium">
						<f:selectItem itemLabel="" itemValue="" />
						<f:selectItems value="#{cc.attrs.listBean.listAll()}" var="elem" itemLabel="#{elem[cc.attrs.childField]}" itemValue="#{elem}" />
						<f:converter binding="#{entityConverter}" />
					</h:selectOneMenu>
					<h:outputText rendered="#{not cc.editMode}" value="#{cc.entityFromBackingBeanOrAttribute[cc.attrs.field][cc.attrs.childField]}" style="font-weight:bold;" />
			</ui:fragment>

		</ui:fragment>
	</cc:implementation>

</html>
